//
//  Fourth.m
//  A段项目
//
//  Created by dllo on 16/1/22.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "Fourth.h"
#import "NetWorkingHandler.h"
#import "Model.h"
#import "CircleCell.h"
#import "TouchFirstView.h"
#import <DKNightVersion.h>

@interface Fourth ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, retain) NSMutableArray *arrModel;
@property (nonatomic, retain) UITableView *tableView;




@end

@implementation Fourth

{
    CGFloat height;
    
    double YcontentOffset; //记录 tablewview 的偏移量  为了reloaddata 是 tableview 的偏移量不变.
    double HeightForSize;
    
    double ratio; // 比例
    
}

- (void)dealloc {
    
    
    [_arrModel release];
    
    [_tableView release];
    
    
    
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self dataArrayModel];
    
    [self handleData];
  
    [self createTableView];
    
}

- (NSArray *)dataArrayModel {
    
    if (self.arrModel == nil) {
        
        self.arrModel = [NSMutableArray array];
        
        return self.arrModel;
    }
    
    return self.arrModel;
}

- (void)handleData {
    
    [NetWorkingHandler netWorkingWithUrl:@"http://mapp.tiankong.com/action/list?pageSize=30" complete:^(id result) {
        
        for (NSDictionary *dic in [result objectForKey:@"data"]) {
            
            Model *model = [[Model alloc] init];
            
            [model setValuesForKeysWithDictionary:dic];
            
            [self.arrModel addObject:model];
            
            [model release];
    
        }
    
        [self.tableView reloadData];
    }];
    
}

- (void)createTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:0];
    
    [self.view addSubview:self.tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.tableView registerClass:[CircleCell class] forCellReuseIdentifier:@"pool1"];
    
    self.tableView.separatorStyle = 0;
    
    [_tableView release];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.arrModel.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CircleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool1"];
    
  height = [cell passedInfo:[self.arrModel objectAtIndex:indexPath.row]];

    cell.selectionStyle = 0;
    
    [cell retain];
    
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
  
    
    return height;
    
}



- (void)viewWillAppear:(BOOL)animated {
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"夜间模式"]) {
        
        [DKNightVersionManager nightFalling];
        
    } else {
        
        [DKNightVersionManager dawnComing];
    }
    
    
    self.view.dk_backgroundColorPicker = DKColorWithColors([UIColor blackColor], [UIColor colorWithRed:52 / 256.f green:52 / 256.f blue:52 / 256.f alpha:1]);
    
    self.tableView.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor colorWithRed:52 / 256.f green:52 / 256.f blue:52 / 256.f alpha:1]);
    
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"checkCollect" object:nil];

    
}




- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    
   
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
